<?php

namespace app\store\job;

use app\store\service\GroupOrderService;
use app\store\service\PaymentService;
use think\queue\Job;

class Refund
{
    /**
     * 退款申请队列
     * */
    public function fire(Job $job, $data)
    {

        $out_refund_no = PaymentService::generateOrderNum();
        $data['out_refund_no'] = $out_refund_no;
        try {
            GroupOrderService::saveSystemRefundRecord($data);
            $result = PaymentService::groupActivityRefund($data);
            if ($result){
                GroupOrderService::changeGroupOrderAfterStatus($data['group_order_id']);
                $job->delete();
            }
        }catch (\Exception $e){
            if ($job->attempts()>2){
                $job->delete();
            }
        }
    }



}